package com.wanjl.aop.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author WanJl
 * @version 1.0
 * @title ResourceAspect
 * @description
 * @create 2024/11/9
 */
@Component
@Aspect
public class ResourceAspect {

    //切点方法
    @Pointcut("execution(boolean com.wanjl.aop.service.ResourceService.openURL(*,*))")
    private void pt(){}


    //通知方法
    @Around("pt()")
    public Object trimString(ProceedingJoinPoint pjp) throws Throwable {
        //1、先拿到被增强的方法的参数
        Object[] args = pjp.getArgs();
        //2、去除空格操作
        for (int i = 0; i < args.length; i++) {
            //判断参数是不是字符串
            if (args[i].getClass() == String.class) {
                //删除空格
                args[i] = ((String) args[i]).trim();
            }

        }
        //3、把参数还回去
        Object object = pjp.proceed(args);
        return object;
    }

}
